// pages/banghui/chengyuan.js
const app = getApp();
var util = require('../../utils/util.js')
var http = require('../../utils/server.js')
Page({

  data: {
    showDialog: false,
    id: null,
    data: [],
    gang_role: 0
  },
  onLoad: function(options) {
    console.info(options)
    this.setData({
      id: options.gang_id || ''
    })
    var that = this;
    try {
      var value = wx.getStorageSync('userInfo');
      console.info(value);
      if (value) {
        that.data.gang_role = value.gangRole;
      }
    } catch (e) {}

    http.post({
      url: "Gang/getMemberList",
      id: options.gang_id,
      type: ''
    }, function(data) {
      console.log('帮会成员', data);
      that.setData({
        data: data,
        gang_role: that.data.gang_role
      });
    })
  },
  del: function(e) {
    var that = this;
    wx.showModal({
      title: '操作提示',
      content: '确定删除该成员?',
      success: function(res) {
        if (res.confirm) {
          http.post({
            url: "Gang/kickOutGang",
            user_id: e.currentTarget.dataset.id,
          }, function(data) {
            wx.redirectTo({
              url: "/pages/banghui/chengyuan?gang_id=" + that.data.id,
            })
          })
        }
      }
    })
  },
  toggleDialog: function() {
    this.setData({
      showDialog: false,
    })
  },
  userinfo: function(e) {
    var that = this;
    http.post({
      url: "Gang/getMemberInfo",
      id: e.currentTarget.dataset.id,
      type: ''
    }, function(data) {
      console.log('成员详情', data);
      var tags = [];
      var shopInfo = data.shop_info;
      for (var i in shopInfo.tags) {
        var item = {};
        item.name = data.config_tags[i];
        item.good = i < 100;
        item.count = shopInfo.tags[i];
        tags.push(item);
      }
      console.info("tags", tags);
      data.tags = tags;
      that.setData({
        showDialog: true,
        userInfo: data
      })
    })


  },
  toXiaodian: function() {
    var that = this;
    wx.navigateTo({
      url: '/pages/user/xiaodian?id=' + that.data.userInfo.shop_info[0].id + "&uid=" + that.data.userInfo.id,
    })
  }
})